//
// Copyright 2022 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// Selector '.mdc-*' should only be used in this project.
// stylelint-disable selector-class-pattern --
// Internal styling for Tooltip MDC component.

@use '@material/theme/keys';
@use '@material/theme/theme';
@use '@material/tokens/resolvers';
@use '@material/typography/typography';
@use './tooltip-theme';
@use 'sass:map';

$custom-property-prefix: 'plain-tooltip';
$light-theme: (
  container-color: null,
  container-shape: null,
  supporting-text-color: null,
  supporting-text-font: null,
  supporting-text-line-height: null,
  supporting-text-size: null,
  supporting-text-tracking: null,
  supporting-text-type: null,
  supporting-text-weight: null,
);

@mixin theme($theme, $resolvers: resolvers.$material) {
  @include theme.validate-theme($light-theme, $theme);
  $theme: _resolve-theme($theme, $resolvers);
  @include keys.declare-custom-properties(
    $theme,
    $prefix: $custom-property-prefix
  );
}

@mixin theme-styles($theme, $resolvers: resolvers.$material) {
  @include theme.validate-theme-styles($light-theme, $theme);
  $theme: _resolve-theme($theme, $resolvers);
  $theme: keys.create-theme-properties(
    $theme,
    $prefix: $custom-property-prefix
  );

  @include tooltip-theme.fill-color(map.get($theme, 'container-color'));
  @include tooltip-theme.shape-radius(map.get($theme, 'container-shape'));
  @include tooltip-theme.label-ink-color(
    map.get($theme, 'supporting-text-color')
  );

  .mdc-tooltip__surface {
    @include typography.theme-styles(
      (
        font: map.get($theme, 'supporting-text-font'),
        line-height: map.get($theme, 'supporting-text-line-height'),
        size: map.get($theme, 'supporting-text-size'),
        weight: map.get($theme, 'supporting-text-weight'),
        tracking: map.get($theme, 'supporting-text-tracking'),
      )
    );
  }
}

@function _resolve-theme($theme, $resolvers) {
  $theme: map.merge(
    $theme,
    _resolve-theme-typography($theme, map.get($resolvers, 'typography'))
  );
  @return $theme;
}

@function _resolve-theme-typography($theme, $resolver) {
  @return typography.resolve-theme($theme, $resolver, 'supporting-text');
}
